package com.xhu.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 处理mybatis-plus的自动填充
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    private static final String FORMAT = "yyyy-MM-dd HH:mm:ss";


    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new SimpleDateFormat(FORMAT).format(new Date()), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new SimpleDateFormat(FORMAT).format(new Date()), metaObject);
    }
}
